home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4705 < prev    next >
Encoding:
Text File  |  1996-08-05  |  821 b   |  30 lines

  1. Newsgroups: comp.lang.c
  2. Path: undergrad.math.uwaterloo.ca!news
  3. From: Jose Felix Sandoval <jfsandov>
  4. Subject: Re: Help on random numbers
  5. Sender: news@undergrad.math.uwaterloo.ca (news spool owner)
  6. Message-ID: <DMD3oo.1CF@undergrad.math.uwaterloo.ca>
  7. Date: Tue, 6 Feb 1996 16:12:24 GMT
  8. X-Url: news:4f7193$4bi@jaring.my
  9. Content-Transfer-Encoding: 7bit
  10. Content-Type: text/plain; charset=us-ascii
  11. References: <4f7193$4bi@jaring.my>
  12. Nntp-Posting-Host: zeno01.math.uwaterloo.ca
  13. Mime-Version: 1.0
  14. X-Mailer: Mozilla 1.12 (X11; I; AIX 2)
  15. Organization: University of Waterloo
  16.  
  17. Use the time() function in the srand() function.
  18. i.e.
  19.  for ( i = 0; i<10; i++ ) {
  20.     delay(1000);   <- Clock is too fast...
  21.     srand(time(NULL));
  22.     cout << rand() % 10;
  23.   }
  24.  
  25. Will give 10 random numbers from 0 - 9...
  26.  
  27. -- 
  28. Jose Sandoval | jfsandov@uwaterloo.ca
  29.  
  30.